package com.xzcedu.dao_.exercise;

import com.xzcedu.dao_.dao.GoodsDAO;
import com.xzcedu.dao_.domain.Goods;
import org.junit.jupiter.api.Test;

import java.util.List;

/**
 * @author 徐州城
 * @version 1.0
 * 课后练习
 * 开发GoodsDao和Goods，完成对goods表达crud
 */
public class exercise01 {

    //演示对goods表的 CRUD操作
    @Test
    public void testCRUD(){

        GoodsDAO goodsDAO = new GoodsDAO();
        //1. 查询单行单列数据
        Object o = goodsDAO.queryScalar("select goods_name from goods where id = ?", 10);
        System.out.println("===查询单行单列数据===");
        System.out.println(o);

        //2. 查询单行数据
        Goods g = goodsDAO.querySingle("select * from goods where id = ?", Goods.class, 20);
        System.out.println("===查询单行记录===");
        System.out.println(g);

        //3. 查询多行数据
        List<Goods> goods = goodsDAO.queryMultiply("select * from goods where id >= ?", Goods.class, 10);
        System.out.println("===查询多行数据===");
        for (Goods good :goods) {
            System.out.println(good);
        }

        //4. CRUD 操作
        int rows = goodsDAO.update("insert into goods values(?, ?, ?)", 50, "诺基亚手机", 400.0);
        System.out.println(rows > 0 ? "执行成功" : "执行没有影响表");
    }
}
